home *** CD-ROM | disk | FTP | other *** search
/ Nautilus 1992 July / Nautilus-3-8 / Nautilus-3-8.bin / Tools & Utilities / Hacks Pt.1 ƒ / Chassis 4.2.1 ƒ / myActionProc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-14  |  4.6 KB  |  127 lines

  1. /************************************************************************************/
  2. /*    myActionProc                                                                    */
  3. /*    Called when there is a mouse click on a control part.                            */
  4. /*                                                                                    */
  5. /*    Note:    although the physical location of destRect doesn't change, scrolling    */
  6. /*            and autoscroll change the value of destRect.top                            */
  7. /************************************************************************************/
  8.  
  9. #include "MyHeaders.h"
  10.  
  11. pascal Boolean myActionProc(ControlHandle theControl, short partCode)
  12. {
  13.     int                MAPRetCode;
  14.     WindowPtr        theWindow;
  15.     TEHandle        theTE;
  16.     int                vView;                        /* height of viewRect rounded        */
  17.     int                vViewP;                        /* height of viewRect not rounded    */
  18.     int                vLine;                        /* height of one line of text        */
  19.     int                vTotal;                        /* total height of text                */
  20.     int                vAmount;                    /* total amount that can be scroled    */
  21.     int                vScrlAmt;                    /* scroll amount                    */
  22.     div_t            r;                            /* work area for division            */
  23.     int                tAdjust;                    /* amount to adjust thumb scrolling    */
  24.     
  25.     MAPRetCode = TRUE;
  26.     
  27.     theWindow = ((WindowPtr) (**theControl).contrlOwner);        /* ptr to window    */
  28.     WhichWindow (theWindow, &windSub);                            /* subscr to table    */
  29.     theTE = windTbl[windSub].windTEH[0];                        /* handle to TE rec    */
  30.  
  31.     vLine = (**theTE).lineHeight;                                /* height of 1 line    */
  32.     vViewP = (**theTE).viewRect.bottom -(**theTE).viewRect.top;    /* height of 1 page    */
  33.     vView = (vViewP / vLine) * vLine;                            /* rounded to lines    */
  34.     vTotal = (**theTE).nLines * (**theTE).lineHeight;            /* height whole txt    */
  35.     if ((**theTE).teLength > 0                                     /* if ends in c/r    */
  36.         && (*((**theTE).hText))[(**theTE).teLength-1]=='\r')    /*    adjust for it    */
  37.             vTotal += (**theTE).lineHeight;
  38.  
  39.     switch (partCode)
  40.         {
  41.         case (inUpButton):
  42.             vScrlAmt = ((**theTE).viewRect.top > (**theTE).destRect.top + vLine)
  43.                     ? vLine
  44.                     : (**theTE).viewRect.top - (**theTE).destRect.top;
  45.         break;
  46.                 
  47.         case (inPageUp):
  48.             vScrlAmt = ((**theTE).viewRect.top > (**theTE).destRect.top + vView)
  49.                     ? vView
  50.                     : (**theTE).viewRect.top - (**theTE).destRect.top;
  51.         break;
  52.         
  53.         case (inPageDown):
  54.             vScrlAmt = ((**theTE).viewRect.bottom 
  55.                         < (**theTE).destRect.top + vTotal - vView) 
  56.                     ? -vView 
  57.                     : -((**theTE).destRect.top + vTotal - (**theTE).viewRect.bottom);
  58.         break;
  59.                 
  60.         case (inDownButton):
  61.             vScrlAmt = ((**theTE).viewRect.bottom 
  62.                         < (**theTE).destRect.top + vTotal - vLine) 
  63.                     ? -vLine 
  64.                     : -((**theTE).destRect.top + vTotal - (**theTE).viewRect.bottom);
  65.         break;
  66.         
  67.         case (inThumb):
  68.                                                 /* current value of control            */
  69.             j = GetCtlValue (theControl);        /*   after moving thumb                */
  70.             
  71.                                                 /* difference in control value        */
  72.             vScrlAmt = k;                        /*   due to moving thumb            */
  73.             
  74.                                                 /* how much more or less than whole    */
  75.             r = div (vScrlAmt, vLine);            /*   number of lines in the scroll?    */
  76.             
  77.                                                 /* compute adjustment to the scroll    */
  78.                                                 /*   amount and the control value    */
  79.                                                 /*   to result in only scrolling a    */
  80.                                                 /*   whole number of lines            */
  81.                                                 
  82.             if (abs(r.rem) < vLine/2)                /* if we should round down        */
  83.                 tAdjust = -r.rem;                    /*   use this                    */
  84.             else                                    /* else                            */
  85.                 {                                    /* if we should round up        */
  86.                 if (r.rem > 0)                        /*   if we are scrolling up        */
  87.                     tAdjust = -r.rem + vLine;        /*        use this                */
  88.                 else                                /*   else if scrolling down        */
  89.                     tAdjust = -r.rem - vLine;        /*      use this                */
  90.                 }
  91.                     
  92.             vScrlAmt += tAdjust;                /* adjust scroll amt (scroll later)    */
  93.             
  94.             if (tAdjust != 0)                    /* adjust control amount and redraw    */
  95.                 SetCtlValue (theControl, (j - tAdjust));
  96.         break;
  97.         
  98.         case (0):
  99.             vScrlAmt = 0;
  100.                                                 /* If the total vertical length of    */
  101.                                                 /* the text now is less than the    */
  102.                                                 /* height of the viewRect, prepare    */
  103.                                                 /* to scroll to the top of viewRect    */
  104.             if ((vViewP >= vTotal)
  105.                     && ((**theTE).viewRect.top != (**theTE).destRect.top))
  106.                 vScrlAmt = (**theTE).viewRect.top - (**theTE).destRect.top;    
  107.         break;
  108.         
  109.         default:
  110.             return MAPRetCode;
  111.         }
  112.         
  113.     TEScroll (0, vScrlAmt, theTE);                            /* do the scroll        */            
  114.  
  115.     vAmount = (vTotal > vViewP) ? vTotal-vViewP : 0;        /* ..max scrollable amt    */
  116.     if (vAmount == 0)                                        /* ..if view > text        */
  117.         (**theTE).destRect.top = (**theTE).viewRect.top;    /* ..  fit all in view    */
  118.     
  119.     if (GetCtlMax (theControl) != vAmount)                    /* set max to..            */
  120.         SetCtlMax(theControl, vAmount);                        /* .. max scrollable    */
  121.         
  122.     if (partCode != inThumb)                                /* reset and redraw        */
  123.         SetCtlValue (theControl, ((**theTE).viewRect.top) - (**theTE).destRect.top);
  124.     
  125.     return    MAPRetCode; 
  126. }
  127.